package com.cqust.wdm.emsboot.controller;

import com.cqust.wdm.emsboot.domain.Warehouse;
import com.cqust.wdm.emsboot.service.IWarehouseService;
import com.cqust.wdm.emsboot.util.AjaxResult;
import com.cqust.wdm.emsboot.util.BaseController;
import com.cqust.wdm.emsboot.util.page.TableDataInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仓库信息Controller
 *
 * @author ${author}

 */
@RestController
@RequestMapping("/emsboot/warehouse")
public class WarehouseController extends BaseController {
    @Autowired
    private IWarehouseService warehouseService;

    /**
     * 查询仓库信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Warehouse warehouse) {
        startPage();
        List<Warehouse> list = warehouseService.selectWarehouseList(warehouse);
        return getDataTable(list);
    }


    /**
     * 获取仓库信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(warehouseService.selectWarehouseById(id));
    }

    /*
     * 新增仓库信息
     */
    @ApiOperation("新增仓库信息")
    @PostMapping
    public AjaxResult add(@RequestBody Warehouse warehouse) {
        return toAjax(warehouseService.insertWarehouse(warehouse));
    }

    /**
     * 修改仓库信息
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Warehouse warehouse) {
        return toAjax(warehouseService.updateWarehouse(warehouse));
    }

    /**
     * 删除仓库信息
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(warehouseService.deleteWarehouseByIds(ids));
    }
}
